{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Support Vector Machine Part 2"
      ],
      "metadata": {}
    },
    {
      "cell_type": "markdown",
      "source": [
        "Support Vector Machines(SVM) is use to solve both linear and non-linear models. SVM is used for classification or regression problems. In addition, is a method that transform the data and figures the data transformations by finding optimal boundary between the outputs. "
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import pandas as pd\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "# fix_yahoo_finance is used to fetch data \n",
        "import fix_yahoo_finance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2018-01-01'\n",
        "end = '2018-02-01'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# View Columns\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 2,
          "data": {
            "text/plain": [
              "             Open   High    Low  Close  Adj Close     Volume\n",
              "Date                                                        \n",
              "2018-01-02  10.42  11.02  10.34  10.98      10.98   44146300\n",
              "2018-01-03  11.61  12.14  11.36  11.55      11.55  154066700\n",
              "2018-01-04  12.10  12.43  11.97  12.12      12.12  109503000\n",
              "2018-01-05  12.19  12.22  11.66  11.88      11.88   63808900\n",
              "2018-01-08  12.01  12.30  11.85  12.28      12.28   63346000"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2018-01-02</th>\n",
              "      <td>10.42</td>\n",
              "      <td>11.02</td>\n",
              "      <td>10.34</td>\n",
              "      <td>10.98</td>\n",
              "      <td>10.98</td>\n",
              "      <td>44146300</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-03</th>\n",
              "      <td>11.61</td>\n",
              "      <td>12.14</td>\n",
              "      <td>11.36</td>\n",
              "      <td>11.55</td>\n",
              "      <td>11.55</td>\n",
              "      <td>154066700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-04</th>\n",
              "      <td>12.10</td>\n",
              "      <td>12.43</td>\n",
              "      <td>11.97</td>\n",
              "      <td>12.12</td>\n",
              "      <td>12.12</td>\n",
              "      <td>109503000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-05</th>\n",
              "      <td>12.19</td>\n",
              "      <td>12.22</td>\n",
              "      <td>11.66</td>\n",
              "      <td>11.88</td>\n",
              "      <td>11.88</td>\n",
              "      <td>63808900</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-08</th>\n",
              "      <td>12.01</td>\n",
              "      <td>12.30</td>\n",
              "      <td>11.85</td>\n",
              "      <td>12.28</td>\n",
              "      <td>12.28</td>\n",
              "      <td>63346000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset['Increase_Decrease'] = np.where(dataset['Volume'].shift(-1) > dataset['Volume'],1,0)\n",
        "dataset['Buy_Sell_on_Open'] = np.where(dataset['Open'].shift(-1) > dataset['Open'],1,0)\n",
        "dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,0)\n",
        "dataset['Returns'] = dataset['Adj Close'].pct_change()\n",
        "dataset = dataset.dropna()\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 3,
          "data": {
            "text/plain": [
              "             Open   High    Low  Close  Adj Close     Volume  \\\n",
              "Date                                                           \n",
              "2018-01-03  11.61  12.14  11.36  11.55      11.55  154066700   \n",
              "2018-01-04  12.10  12.43  11.97  12.12      12.12  109503000   \n",
              "2018-01-05  12.19  12.22  11.66  11.88      11.88   63808900   \n",
              "2018-01-08  12.01  12.30  11.85  12.28      12.28   63346000   \n",
              "2018-01-09  12.00  12.02  11.71  11.82      11.82   62560900   \n",
              "\n",
              "            Increase_Decrease  Buy_Sell_on_Open  Buy_Sell   Returns  \n",
              "Date                                                                 \n",
              "2018-01-03                  0                 1         1  0.051913  \n",
              "2018-01-04                  0                 1         0  0.049351  \n",
              "2018-01-05                  0                 0         1 -0.019802  \n",
              "2018-01-08                  0                 0         0  0.033670  \n",
              "2018-01-09                  0                 0         1 -0.037459  "
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "      <th>Increase_Decrease</th>\n",
              "      <th>Buy_Sell_on_Open</th>\n",
              "      <th>Buy_Sell</th>\n",
              "      <th>Returns</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2018-01-03</th>\n",
              "      <td>11.61</td>\n",
              "      <td>12.14</td>\n",
              "      <td>11.36</td>\n",
              "      <td>11.55</td>\n",
              "      <td>11.55</td>\n",
              "      <td>154066700</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.051913</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-04</th>\n",
              "      <td>12.10</td>\n",
              "      <td>12.43</td>\n",
              "      <td>11.97</td>\n",
              "      <td>12.12</td>\n",
              "      <td>12.12</td>\n",
              "      <td>109503000</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0.049351</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-05</th>\n",
              "      <td>12.19</td>\n",
              "      <td>12.22</td>\n",
              "      <td>11.66</td>\n",
              "      <td>11.88</td>\n",
              "      <td>11.88</td>\n",
              "      <td>63808900</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-0.019802</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-08</th>\n",
              "      <td>12.01</td>\n",
              "      <td>12.30</td>\n",
              "      <td>11.85</td>\n",
              "      <td>12.28</td>\n",
              "      <td>12.28</td>\n",
              "      <td>63346000</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.033670</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-09</th>\n",
              "      <td>12.00</td>\n",
              "      <td>12.02</td>\n",
              "      <td>11.71</td>\n",
              "      <td>11.82</td>\n",
              "      <td>11.82</td>\n",
              "      <td>62560900</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-0.037459</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset['Target'] = 0\n",
        "dataset.loc[dataset['Returns']>0, 'Target'] = 1\n",
        "dataset.loc[dataset['Returns']<0, 'Target'] = -1"
      ],
      "outputs": [],
      "execution_count": 4,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 5,
          "data": {
            "text/plain": [
              "             Open   High    Low  Close  Adj Close     Volume  \\\n",
              "Date                                                           \n",
              "2018-01-03  11.61  12.14  11.36  11.55      11.55  154066700   \n",
              "2018-01-04  12.10  12.43  11.97  12.12      12.12  109503000   \n",
              "2018-01-05  12.19  12.22  11.66  11.88      11.88   63808900   \n",
              "2018-01-08  12.01  12.30  11.85  12.28      12.28   63346000   \n",
              "2018-01-09  12.00  12.02  11.71  11.82      11.82   62560900   \n",
              "\n",
              "            Increase_Decrease  Buy_Sell_on_Open  Buy_Sell   Returns  Target  \n",
              "Date                                                                         \n",
              "2018-01-03                  0                 1         1  0.051913       1  \n",
              "2018-01-04                  0                 1         0  0.049351       1  \n",
              "2018-01-05                  0                 0         1 -0.019802      -1  \n",
              "2018-01-08                  0                 0         0  0.033670       1  \n",
              "2018-01-09                  0                 0         1 -0.037459      -1  "
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "      <th>Increase_Decrease</th>\n",
              "      <th>Buy_Sell_on_Open</th>\n",
              "      <th>Buy_Sell</th>\n",
              "      <th>Returns</th>\n",
              "      <th>Target</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2018-01-03</th>\n",
              "      <td>11.61</td>\n",
              "      <td>12.14</td>\n",
              "      <td>11.36</td>\n",
              "      <td>11.55</td>\n",
              "      <td>11.55</td>\n",
              "      <td>154066700</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>1</td>\n",
              "      <td>0.051913</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-04</th>\n",
              "      <td>12.10</td>\n",
              "      <td>12.43</td>\n",
              "      <td>11.97</td>\n",
              "      <td>12.12</td>\n",
              "      <td>12.12</td>\n",
              "      <td>109503000</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0.049351</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-05</th>\n",
              "      <td>12.19</td>\n",
              "      <td>12.22</td>\n",
              "      <td>11.66</td>\n",
              "      <td>11.88</td>\n",
              "      <td>11.88</td>\n",
              "      <td>63808900</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-0.019802</td>\n",
              "      <td>-1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-08</th>\n",
              "      <td>12.01</td>\n",
              "      <td>12.30</td>\n",
              "      <td>11.85</td>\n",
              "      <td>12.28</td>\n",
              "      <td>12.28</td>\n",
              "      <td>63346000</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0.033670</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2018-01-09</th>\n",
              "      <td>12.00</td>\n",
              "      <td>12.02</td>\n",
              "      <td>11.71</td>\n",
              "      <td>11.82</td>\n",
              "      <td>11.82</td>\n",
              "      <td>62560900</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-0.037459</td>\n",
              "      <td>-1</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 5,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Data pre-processing and selection"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "features_df = dataset[['Open', 'High', 'Low', 'Adj Close', 'Returns']] \n",
        "X = np.asarray(features_df) # Features\n",
        "X[0:5]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 6,
          "data": {
            "text/plain": [
              "array([[11.61      , 12.14      , 11.36      , 11.55      ,  0.05191257],\n",
              "       [12.1       , 12.43      , 11.97      , 12.12      ,  0.04935065],\n",
              "       [12.19      , 12.22      , 11.66      , 11.88      , -0.01980198],\n",
              "       [12.01      , 12.3       , 11.85      , 12.28      ,  0.03367003],\n",
              "       [12.        , 12.02      , 11.71      , 11.82      , -0.03745928]])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 6,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "target = dataset['Buy_Sell'].astype('int')\n",
        "Y = np.asarray(target)  # Target variable\n",
        "Y[0:5]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 7,
          "data": {
            "text/plain": [
              "array([1, 0, 1, 0, 1])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 7,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(X.shape)\n",
        "print(Y.shape)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "(21, 5)\n",
            "(21,)\n"
          ]
        }
      ],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# split X and y into training and testing sets\n",
        "from sklearn.cross_validation import train_test_split\n",
        "X_train,X_test,y_train,y_test=train_test_split(X,Y,test_size=0.20)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "C:\\Users\\Tin Hang\\Anaconda3\\envs\\py35\\lib\\site-packages\\sklearn\\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.\n",
            "  \"This module will be removed in 0.20.\", DeprecationWarning)\n"
          ]
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print ('Train set:', X_train.shape,  y_train.shape)\n",
        "print ('Test set:', X_test.shape,  y_test.shape)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Train set: (16, 5) (16,)\n",
            "Test set: (5, 5) (5,)\n"
          ]
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Modelling SVM"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn import svm\n",
        "clf = svm.SVC(kernel='rbf')\n",
        "clf.fit(X_train, y_train) "
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 11,
          "data": {
            "text/plain": [
              "SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,\n",
              "  decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',\n",
              "  max_iter=-1, probability=False, random_state=None, shrinking=True,\n",
              "  tol=0.001, verbose=False)"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 11,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "yhat = clf.predict(X_test)\n",
        "yhat [0:5]"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 12,
          "data": {
            "text/plain": [
              "array([0, 1, 1, 1, 1])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Evaluation"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.metrics import classification_report, confusion_matrix\n",
        "import itertools"
      ],
      "outputs": [],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def plot_confusion_matrix(cm, classes,\n",
        "                          normalize=False,\n",
        "                          title='Confusion matrix',\n",
        "                          cmap=plt.cm.Blues):\n",
        "    \"\"\"\n",
        "    This function prints and plots the confusion matrix.\n",
        "    Normalization can be applied by setting `normalize=True`.\n",
        "    \"\"\"\n",
        "    if normalize:\n",
        "        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
        "        print(\"Normalized confusion matrix\")\n",
        "    else:\n",
        "        print('Confusion matrix, without normalization')\n",
        "\n",
        "    print(cm)\n",
        "\n",
        "    plt.imshow(cm, interpolation='nearest', cmap=cmap)\n",
        "    plt.title(title)\n",
        "    plt.colorbar()\n",
        "    tick_marks = np.arange(len(classes))\n",
        "    plt.xticks(tick_marks, classes, rotation=45)\n",
        "    plt.yticks(tick_marks, classes)\n",
        "\n",
        "    fmt = '.2f' if normalize else 'd'\n",
        "    thresh = cm.max() / 2.\n",
        "    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):\n",
        "        plt.text(j, i, format(cm[i, j], fmt),\n",
        "                 horizontalalignment=\"center\",\n",
        "                 color=\"white\" if cm[i, j] > thresh else \"black\")\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.ylabel('True label')\n",
        "    plt.xlabel('Predicted label')"
      ],
      "outputs": [],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Compute confusion matrix\n",
        "cnf_matrix = confusion_matrix(y_test, yhat, labels=[1,4])\n",
        "np.set_printoptions(precision=2)\n",
        "\n",
        "print (classification_report(y_test, yhat))\n",
        "\n",
        "# Plot non-normalized confusion matrix\n",
        "plt.figure()\n",
        "plot_confusion_matrix(cnf_matrix, classes=['Benign(2)','Malignant(4)'],normalize= False,  title='Confusion matrix')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "             precision    recall  f1-score   support\n",
            "\n",
            "          0       1.00      0.50      0.67         2\n",
            "          1       0.75      1.00      0.86         3\n",
            "\n",
            "avg / total       0.85      0.80      0.78         5\n",
            "\n",
            "Confusion matrix, without normalization\n",
            "[[3 0]\n",
            " [0 0]]\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 2 Axes>"
            ],
            "image/png": [
              "iVBORw0KGgoAAAANSUhEUgAAAVYAAAEmCAYAAAA5jbhCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xm8XdP9//HX+2aQaIISRQZiVlKCGEqpThpD0ZaKolUtv6oOSvnS+mrpt6Xtt6aGapQqWlJKmwpFW2r4SkgihtSQmCqJIoYQMkjy+f2x1tXj9t5zzs3d555zct9Pj/1w9t7rrP25J8nnrrP2WmsrIjAzs+K01DsAM7OVjROrmVnBnFjNzArmxGpmVjAnVjOzgjmxmpkVzInV6kpSf0l/kjRf0jVdqOdQSbcUGVu9SNpN0mP1jsNWnDyO1aoh6bPA8cAWwOvAdOAHEXFXF+s9HPgasEtELO1yoA1OUgCbRsSsesditeMWq1Uk6XjgXOCHwDrA+sCFwP4FVL8B8HhPSKrVkNS73jFYASLCm7cON2B1YAFwUJkyq5AS79y8nQusks/tAcwGTgBeAJ4DvpDPnQ4sAd7K1/gi8D3gypK6hwMB9M77RwBPklrNTwGHlhy/q+R9uwD3AfPz/3cpOXc78H3g7lzPLcCgDn621vhPKon/AGBv4HHgZeDbJeV3BO4BXs1lxwJ987k78s/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GXA/PwI6VJ75u3+vD+AlGgHAtdHxJv5GhOq+JlGSPofUnfDANKKVq1+FxHLgZmSnsw/w57A1iX9r6vnaz9exbWsSTmxWi0tjIiRpQdy8nyj9BBwa0Qc0qbcSNLjTIog4MyI+EWbaxy3Ate4DDggIh6QdASwR8m5tnVFvvbXIqI0ASNpeCeva03EXQFWb5OAXSVtAiBpVUmbAY8CG0raOJc7pIP3/xU4Jr+3l6TVgNdJrdFWNwNHlvTdDpH0HuAO4JOS+ksaSOp2qGQg8JykPqRHWJc6SFJLjnkj0kMFbwaOyeWRtJmkd1VxHWtibrFaXUXEi7nld5WkVfLhUyPicUlHAxMlzQPuAka0U8U3gHGSvggsA46JiHsk3Z2HM92U+1nfC9yTW8wLgMMiYpqk8cB04BlSd0Ul/016KsAzpD7j0gT+GPB3YB3gyxGxSNIvSX2v0/IjW14kPfPKVmJeK8DMrGDuCjAzK5gTq5lZwZxYzcwK5sRqZlYwJ1Yzs4I5sZqZFcyJ1cysYP8fsQRO4neFO88AAAAASUVORK5CYII=\n"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 19,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.metrics import f1_score\n",
        "f1_score(y_test, yhat, average='weighted') "
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 16,
          "data": {
            "text/plain": [
              "0.7809523809523808"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 16,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.metrics import jaccard_similarity_score\n",
        "jaccard_similarity_score(y_test, yhat)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 17,
          "data": {
            "text/plain": [
              "0.8"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 17,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "clf2 = svm.SVC(kernel='linear')\n",
        "clf2.fit(X_train, y_train) \n",
        "yhat2 = clf2.predict(X_test)\n",
        "print(\"Avg F1-score: %.4f\" % f1_score(y_test, yhat2, average='weighted'))\n",
        "print(\"Jaccard score: %.4f\" % jaccard_similarity_score(y_test, yhat2))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Avg F1-score: 0.7810\n",
            "Jaccard score: 0.8000\n"
          ]
        }
      ],
      "execution_count": 18,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "file_extension": ".py",
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "mimetype": "text/x-python",
      "nbconvert_exporter": "python",
      "name": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.5"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}